#include "Main.h"

Player* GetPlayer(DWORD dwSlot)
{
	if(!InGame())
		return NULL;

	if((*p_GAME_GameInfos) && (*p_GAME_GameInfos)->dwPlayerCount > dwSlot)
		return GAME_GetPlayer((*p_GAME_GameInfos), NULL, dwSlot);	

	return NULL;
}

Player* GetPlayer(CHAR* szName)
{
	if(!InGame())
		return NULL;

	if(!(*p_GAME_GameInfos))
		return NULL;

	for(INT i = 0; i < (*p_GAME_GameInfos)->dwMaxPlayerCount; i++)
	{
		CHAR* szPlayerName = GAME_GetPlayerName(i);

		if(!szPlayerName)
			continue;

		if(strstr(szPlayerName, szName))
			return GetPlayer(i);
	}

	return NULL;
}

Player* GetNextPlayer(DWORD dwCurrentSlot, CHAR* szName)
{
	if(!szName || !*szName)
		return GetPlayer(dwCurrentSlot+1);

	if(!(*p_GAME_GameInfos))
		return NULL;

	for(INT i = dwCurrentSlot; i < (*p_GAME_GameInfos)->dwMaxPlayerCount; i++)
	{
		CHAR* szPlayerName = GAME_GetPlayerName(i);

		if(!szPlayerName)
			continue;

		if(strstr(szPlayerName, szName))
			return GetPlayer(i);		
	}
	
	return NULL;
}
